<?php

/**
 * Pwiff - PHP SWF Library
 *
 * LICENSE
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 *
 * @package    Pwiff
 * @subpackage Records
 * @copyright  Copyright (c) 2010 Steven Harris
 * @license    http://www.opensource.org/licenses/bsd-license.php New BSD License
 * @version    $Id: LanguageCode.php 5 2010-02-14 05:08:39Z indigo.sunrise $
 */

/**
 * Represents a language code in an SWF file.
 *
 * @package    Pwiff
 * @subpackage Records
 */
class Pwiff_Record_LanguageCode extends Pwiff_Record
{
	/**#@+
	 * Language code constants.
	 *
	 * @var int
	 */
	const LATIN    = 1;
	const JAPANESE = 2;
	const KOREAN   = 3;
	const CHINESE_SIMPLIFIED  = 4;
	const CHINESE_TRADITIONAL = 5;
	/**#@-*/
	
	/**
	 * Language code value.
	 *
	 * @var int
	 */
	protected $code = 1;
	
	/**
	 * Sets the language code value.
	 *
	 * @param  int $languageCode
	 */
	public function setCode($languageCode)
	{
		if ($languageCode < self::LATIN OR $languageCode > self::CHINESE_TRADITIONAL) {
			throw new Pwiff_Exception('Invalid language code.');
		}
		$this->code = $languageCode;
	}
	
	/**
	 * Retrieves the language code value.
	 *
	 * @return int
	 */
	public function getCode()
	{
		return $this->code;
	}
	
	/**
	 * Gets the length of this record. Always 1.
	 *
	 * @return int
	 */
	public function getRecordLength()
	{
		return 1;
	}
	
	/**
	 * Writes the language code to the given output instance.
	 *
	 * @param  Pwiff_Output $out
	 */
	public function write(Pwiff_Output $out)
	{
		$out->writeUI8($this->getCode());
	}
}
